Skip to content

Fix task host launch regressions from apphost support#13325

Merged
YuliiaKovalova merged 4 commits intomainfrom
dev/ykovalova/fix-apphost-task-host-launch
Mar 4, 2026
Merged

Fix task host launch regressions from apphost support#13325
YuliiaKovalova merged 4 commits intomainfrom
dev/ykovalova/fix-apphost-task-host-launch

Conversation

@YuliiaKovalova
Copy link
Member

@YuliiaKovalova YuliiaKovalova commented Mar 4, 2026

Summary

Fixes three regressions introduced by #13175 (Add App Host Support for MSBuild, commit c8011cb).

Bug 1: CLR2 task host (MSBuildTaskHost.exe) broken - VS build failures

Root cause: NodeLauncher.ResolveExecutableName only recognized MSBuild.exe (Constants.MSBuildExecutableName) as a native executable. Any other .exe - including MSBuildTaskHost.exe - was treated as a managed assembly and routed through dotnet.exe. Since MSBuildTaskHost.exe is a standalone .NET Framework 3.5 executable, dotnet.exe cannot host it.

Bug 2: .NET task host fallback broken when DotnetHostPath is null

Symptom: MSB4216: ... the required executable "...\sdk\11.0.100-ci\MSBuild.exe" exists and can be run - in CI where the apphost hasn't been created yet.

Root cause: ResolveAppHostOrFallback correctly detects the missing apphost and tries to fall back to dotnet MSBuild.dll, but TaskHostParameters.DotnetHostPath is null (not populated by AssemblyTaskFactory). This produces NodeLaunchData(null, ...) which silently fails in CreateNode.

Bug 3: MSB4216 error shows wrong executable path for .NET task hosts

Root cause: LogErrorUnableToCreateTaskHost in TaskHostTask.cs has a #if NETFRAMEWORK guard around the .NET task host path resolution. On .NET Core (the common case), it always falls through to GetMSBuildExecutablePathForNonNETRuntimes which returns the non-.NET path (MSBuild.exe), even for .NET task host failures.

Three bugs introduced by c8011cb (Add App Host Support for MSBuild):

1. CLR2 task host (MSBuildTaskHost.exe) broken on .NET Core MSBuild:
   ResolveExecutableName only recognized MSBuild.exe as a native executable.
   Any other .exe (like MSBuildTaskHost.exe) was incorrectly routed through
   dotnet.exe, which cannot host .NET Framework 3.5 executables.
   Fix: detect native executables by checking for .dll extension instead of
   matching a specific filename. Only .dll files need dotnet.exe as host.

2. .NET task host fallback broken when DotnetHostPath is null:
   ResolveAppHostOrFallback created NodeLaunchData with null MSBuildLocation
   when apphost was missing and TaskHostParameters.DotnetHostPath was not set.
   Fix: auto-discover dotnet host via CurrentHost.GetCurrentHost() when the
   parameter is null.

3. MSB4216 error shows wrong executable path for .NET task hosts:
   LogErrorUnableToCreateTaskHost had a #if NETFRAMEWORK guard that prevented
   it from using the correct .NET path when running on .NET Core. It always
   showed the non-.NET path (MSBuild.exe) regardless of task host type.
   Fix: check HandshakeOptions.NET on all runtimes, not just .NET Framework.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 4, 2026 10:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes three regressions introduced by PR #13175 (app host support for MSBuild), all related to incorrect task host process launching behavior.

Changes:

  • NodeLauncher.cs: Broadens the "native executable" detection from only MSBuild.exe to all non-.dll files, so MSBuildTaskHost.exe and other .exe launchers are run directly instead of being incorrectly routed through dotnet.exe.
  • NodeProviderOutOfProcTaskHost.cs: Auto-discovers the dotnet host path via CurrentHost.GetCurrentHost() when TaskHostParameters.DotnetHostPath is null, preventing a silent null-MSBuildLocation failure in the fallback code path.
  • TaskHostTask.cs: Removes the #if NETFRAMEWORK guard from the .NET runtime path resolution in LogErrorUnableToCreateTaskHost, so the correct .NET task host path (app host) is shown in error messages on .NET Core builds too.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Build/BackEnd/Components/Communications/NodeLauncher.cs Fixes CLR2 task host (MSBuildTaskHost.exe) being incorrectly launched via dotnet.exe by switching from name-based to extension-based native/managed classification.
src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcTaskHost.cs Adds auto-discovery of the dotnet host path when null, preventing a silent build failure in the app-host-absent fallback path.
src/Build/Instance/TaskFactories/TaskHostTask.cs Removes the #if NETFRAMEWORK guard so that .NET task host error messages always show the correct executable path on all runtimes.

Add two e2e tests to NetTaskHost_E2E_Tests covering the CLR2 task host
scenario that was broken by the apphost changes:

1. CLR2TaskHost_Net35ProjectWithResources_BuildSucceeds:
   Builds a .NET 3.5 WinForms project with embedded resources, which
   triggers GenerateResource via MSBuildTaskHost.exe (CLR2 runtime).
   Verifies no MSB4216 errors occur.

2. CLR2TaskHost_FrameworkTaskWithTaskHostFactory_UsesCorrectProcess:
   Runs the ExampleFrameworkTask through TaskHostFactory, verifying
   the Framework task host launches correctly without MSB4216 errors.

Both tests validate the fix in NodeLauncher.ResolveExecutableName that
detects native executables by .dll extension rather than matching a
specific filename, preventing MSBuildTaskHost.exe from being incorrectly
routed through dotnet.exe.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@YuliiaKovalova YuliiaKovalova marked this pull request as draft March 4, 2026 11:21
@YuliiaKovalova YuliiaKovalova marked this pull request as ready for review March 4, 2026 14:29
YuliiaKovalova added a commit to dotnet/dotnet that referenced this pull request Mar 4, 2026
Apply fixes from dotnet/msbuild#13325:
- ResolveExecutableName: detect native executables by .dll extension check
- ResolveNodeLaunchConfiguration: restore CLR2 branch with proper handshake
- ResolveAppHostOrFallback: auto-discover dotnet host path when not provided
- LogErrorUnableToCreateTaskHost: fix for .NET host context

Experiment to verify if these fixes resolve the VSTestTask failure
in offline source-build.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Member

@JanProvaznik JanProvaznik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok with the last commit I trust it

@JanProvaznik
Copy link
Member

@rainersigwald also ptal

Co-authored-by: Rainer Sigwald <raines@microsoft.com>
@YuliiaKovalova YuliiaKovalova enabled auto-merge (squash) March 4, 2026 17:27
@YuliiaKovalova YuliiaKovalova merged commit b481c50 into main Mar 4, 2026
10 checks passed
@YuliiaKovalova YuliiaKovalova deleted the dev/ykovalova/fix-apphost-task-host-launch branch March 4, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants